package com.wangshouyu.mp.message;

import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author 王守钰
 * @date 2020年12月07日 10:21
 * @description 基本消息
 */
public abstract class BaseMessage implements Serializable {

    /**
     * 接收方帐号（收到的OpenID）
     */
    @XStreamAlias(value = "ToUserName")
    private String toUserName;

    /**
     * 开发者微信号（公众号）
     */
    @XStreamAlias(value = "FromUserName")
    private String fromUserName;

    /**
     * 消息创建时间 （整型）
     */
    @XStreamAlias(value = "CreateTime")
    private long createTime;

    /**
     * 消息类型（text/music/news）
     */
    @XStreamAlias(value = "MsgType")
    private String msgType;

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BaseMessage that = (BaseMessage) o;
        return createTime == that.createTime &&
                Objects.equals(toUserName, that.toUserName) &&
                Objects.equals(fromUserName, that.fromUserName) &&
                Objects.equals(msgType, that.msgType);
    }

    @Override
    public int hashCode() {
        return Objects.hash(toUserName, fromUserName, createTime, msgType);
    }

    @Override
    public String toString() {
        return "BaseMessage{" +
                "toUserName='" + toUserName + '\'' +
                ", fromUserName='" + fromUserName + '\'' +
                ", createTime=" + createTime +
                ", msgType='" + msgType + '\'' +
                '}';
    }
}
